package cn.yx.framework.configuration;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;

@Configuration
@EnableSwagger2
@Import({BaseConstant.class})
class SwaggerConfig {
    @Resource
    private BaseConstant.ApiDocConfig apiDocConfig;

    SwaggerConfig()
    {
    }


    @Bean
    public Docket docket() {
        Contact contact = new Contact(this.apiDocConfig.getTeamName(), this.apiDocConfig.getWebsite(), this.apiDocConfig.getEmail());
        ApiInfo apiInfo = (new ApiInfoBuilder())
                .title(this.apiDocConfig.getTitle())
                .description(this.apiDocConfig.getDescription())
                .termsOfServiceUrl(this.apiDocConfig.getServiceUrl())
                .license(this.apiDocConfig.getLicense())
                .licenseUrl(this.apiDocConfig.getLicenseUrl())
                .contact(contact)
                .version(this.apiDocConfig.getVersion()).build();

        Docket docket = (new Docket(DocumentationType.SWAGGER_2))
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage(BaseConstant.BASE_PACKAGE_CONTROLLER_LAYER))
                .paths(PathSelectors.any())
                .build();
        return docket;

    }
}